﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using BungaloEngine.Managers;

namespace BungaloEngine.Core
{
    class Engine
    {
        public static SpriteBatch pSpriteBatch
        {
            get;
            private set;
        }

        public static TextureManager pTextureManager
        {
            get;
            private set;
        }

        public static AssetManager pAssetManager
        {
            get;
            private set;
        }

        List<IRenderable> _renderables = new List<IRenderable>();
        List<IUpdateable> _updateables = new List<IUpdateable>();

        public void Initialize(SpriteBatch spriteBatch)
        {
            pSpriteBatch = spriteBatch;
            pTextureManager = new TextureManager();
        }

        public bool AddObject(object newObject)
        {
            IRenderable newRenderable = newObject as IRenderable;
            IUpdateable newUpdateable = newObject as IUpdateable;
            if (newRenderable != null)
                _renderables.Add(newRenderable);
            if (newUpdateable != null)
                _updateables.Add(newUpdateable);

            return
                newRenderable != null ||
                newUpdateable != null;
        }

        public void Update(GameTime time)
        {
            for (int i = 0; i < _updateables.Count; i++)
                _updateables[i].Update(time);
        }

        public void Render(GameTime time)
        {
            for (int i = 0; i < _renderables.Count; i++)
                _renderables[i].Render();
        }
    }
}
